﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.SYS.Library;
using ZX.BLL.Extend;
using ZX.DBModule;
using System.Data;
using ZX.Report;

namespace ZX.WebApp.Extend.Reports
{
    public partial class hrDeskReports : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string flag = GetStringFromQueryString("flag", string.Empty);
                if (flag == string.Empty) return;
                DataSet dataSources = null;
                Dictionary<int, string> titles = new Dictionary<int, string>();
                Dictionary<int, int> widths = new Dictionary<int, int>();
                Dictionary<int, int> heights = new Dictionary<int, int>();
                Dictionary<int, string> viewTypes = new Dictionary<int, string>();
                Dictionary<int, int> xyType = new Dictionary<int, int>();
                List<int> seqNum = new List<int>();
                DataTable source = null;
                switch (flag)
                {
                    case "deptEmpCount": //部门人数统计
                        seqNum.Add(1);
                        titles.Add(1, "在职人数统计");
                        widths.Add(1, 1000);
                        heights.Add(1, 500);
                        viewTypes.Add(1, "bar");//柱状显示
                        xyType.Add(1, 1);
                        BaseBussnies deptRportbll = new BaseBussnies();
                        string sql = "select deptname,EmpCount as 人数 from dbo.fn_GetOrganizeEmpCount('" + this.EmpPropertyValues.DeptID.ToString() + "') where level=2";
                        DataTable dt = deptRportbll.GetDataBySqlComm(sql);
                        source = dt.Copy();
                        for (int i = 0; i < source.Rows.Count; i++)
                        {
                            string deptName = source.Rows[i][0].ToString();
                            int index = deptName.LastIndexOf("->");
                            if (index > -1)
                            {
                                deptName = deptName.Substring(index + 2, deptName.Length - index - 2);
                            }
                            source.Rows[i][0] = deptName;
                        }
                        source.TableName = "1";
                        dataSources = new DataSet();
                        dataSources.Tables.Add(source);
                        break;
                }
                if (dataSources == null) return;
                ChartParams paramsFactory = (ChartParams)ParamsFactory.GetInstance(ReportType.Chart, dataSources);
                paramsFactory.Title = titles;
                paramsFactory.Width = widths;
                paramsFactory.Height = heights;
                paramsFactory.SeqNum = seqNum.ToArray();
                paramsFactory.ChartViewType = viewTypes;
                paramsFactory.XYType = xyType;
                ReportFactory reportFactory = ReportFactory.GetInstance(paramsFactory);
                this.ReportViewer.Report = reportFactory.GetReport();
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language='javascript'>alert('生成报表出现错误:" + ex.Message + "');</script>");
            }
        }
    }
}